package br.ufal.ic.utils;
/*
 * Servidor.java
 *
 * Created on 10 de Fevereiro de 2007, 01:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author Paulista
 */
public class RegionServer extends UnicastRemoteObject implements Remote {
    public static String HOST_URL = "rmi://192.168.7.141/SharedMem";
    //public static String HOST_URL = "rmi://bittencourt/SharedMem";
    
    /** Creates a new instance of Servidor */
    public RegionServer() throws RemoteException {
        try {
            //HOST_URL = InetAddress.getLocalHost().getHostAddress() + "/SharedMem";
            HOST_URL = this.HOST_URL;
            System.out.println(InetAddress.getLocalHost().getAddress());
        } catch (UnknownHostException ex) {
            ex.printStackTrace();
        }
        Thread t = new Thread() {
            public void run() {
                try {
                    SharedMem memory = new SharedMem();
                    // evita a utilizacao de rmiregistry
                    LocateRegistry.createRegistry(10100);
                    //LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
                    Naming.rebind("SharedMem", memory);
                    System.out.println("Server started and up.");

                    Object keepAlive = new Object();
                    synchronized(keepAlive ) {
                        keepAlive.wait();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        
        t.start();
    }
    
}
